// 引入一级路由
// import Home from '@/pages/Home/index.vue'
import Login from '@/pages/Login/index.vue'
import Register from '@/pages/Register/index.vue'
import Search from '@/pages/Search/index.vue'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess';
import Center from '@/pages/Center'
// 引入二级路由
import MyOrder from '@/pages/Center/myOrder';
import GroupOrder from '@/pages/Center/groupOrder';
// 对外暴露
export default [{
        path: '/home',
        // 路由懒加载  直接引  作用就是高效
        component: () => import('@/pages/Home'),
        meta: {
            show: true
        }
    },
    {
        path: '/login',
        component: Login,
        meta: {
            show: false
        }
    },
    {
        path: '/register',
        component: Register,
        meta: {
            show: false
        }
    },
    {
        name: 'search',
        path: '/search/:keyword?',
        component: Search,
        meta: {
            show: true
        }
    },
    {
        name: 'detail',
        path: '/detail/:skuId',
        component: Detail,
        meta: {
            show: true
        }
    },
    {
        name: 'addCartSuccess',
        path: '/addcartsuccess',
        component: AddCartSuccess,
        meta: {
            show: true
        }
    },
    {
        name: 'shopcart',
        path: '/shopcart',
        component: ShopCart,
        meta: {
            show: true
        }
    },
    {
        name: 'trade',
        path: '/trade',
        component: Trade,
        meta: {
            show: true
        },
        // 路由独享守卫  只有当从购物车shopcart跳转到trade才能跳转 否者返回原来路径
        beforeEnter: (to, from, next) => {
            if (from.path == '/shopcart') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        name: 'pay',
        path: '/pay',
        component: Pay,
        meta: {
            show: true
        },
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        }
    },
    {
        name: 'paysuccess',
        path: '/paysuccess',
        component: PaySuccess,
        meta: {
            show: true
        },
    },
    {
        name: 'ceter',
        path: '/center',
        component: Center,
        meta: {
            show: true
        },
        children: [{
                path: 'myorder',
                component: MyOrder
            },
            {
                path: 'grouporder',
                component: GroupOrder
            },
            // 重定向 访问center就直接跳转到myorder页面
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    // 重定向
    {
        path: '*',
        redirect: '/home'
    }
]